package com.bank.backend.utils;

import com.bank.backend.model.entity.User;

/**
 * 用户信息持有者
 */
public class UserHolder {
    private static final ThreadLocal<User> tl = new ThreadLocal<>();
    private static final ThreadLocal<Integer> userIdHolder = new ThreadLocal<>();
    private static final ThreadLocal<Boolean> isAdminHolder = new ThreadLocal<>();

    public static void saveUser(User user) {
        tl.set(user);
    }

    public static User getUser() {
        return tl.get();
    }

    public static void removeUser() {
        tl.remove();
        userIdHolder.remove();
        isAdminHolder.remove();
    }

    public static void setUserId(Integer userId) {
        userIdHolder.set(userId);
    }
    public static Integer getUserId() {
        return userIdHolder.get();
    }
    public static void setIsAdmin(Boolean isAdmin) {
        isAdminHolder.set(isAdmin);
    }
    public static Boolean getIsAdmin() {
        return isAdminHolder.get();
    }
} 